<template>
    <div>
        <yh-dialog drag :visible.sync="visibleTemp" width="500px" @close="closeModal" :close-on-click-modal="false">
            <template slot="title">
                禁用计算因子
                <span style="color:#c80000;">(备注：已自动过滤已禁用的指标)</span>
            </template>
            <div>
                <p>{{ list.join(' , ') }}</p>
                <br />
                <hr />
                <br />
                <p>禁用原因:</p>
                <el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="disableReasons" style="margin-top: 5px"> </el-input>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="closeModal">取 消</el-button>
                <el-button size="mini" type="primary" @click="onSubmit">确 定</el-button>
            </div>
        </yh-dialog>
    </div>
</template>

<script lang="ts">
import { Component, Emit, Prop, PropSync, Vue, Watch } from 'vue-property-decorator';
import { updateFactorStatus } from '@/pages/quota/api';
import { DELETE_LOCAL_CACHE } from '@/utils/diction-const-util';

@Component({ name: 'CalculateFactorDisabled' })
export default class CalculateFactorDisabled extends Vue {
    @PropSync('visible') syncVisible: boolean;
    @Prop({ default: () => [] }) list: any[];

    private visibleTemp = false;
    private disableReasons = '';

    @Watch('visible')
    onWatchVisible(value) {
        if (value !== this.visibleTemp) {
            this.visibleTemp = value;
        }
        if (value) {
            this.disableReasons = '';
        }
    }

    // 关闭弹窗
    closeModal() {
        this.syncVisible = false;
    }

    onSubmit() {
        if (!this.disableReasons.trim().length) {
            this.yh_message_error('请填写禁用原因!');
            return;
        } else {
            const data = {
                status: '0',
                codes: this.list,
                disableReasons: this.disableReasons.trim(),
            };
            updateFactorStatus(data).then(res => {
                DELETE_LOCAL_CACHE('CalculateFactor');
                this.yh_message_success('操作成功');
                this.$emit('on-submit');
                this.closeModal();
            });
        }
    }
}
</script>
